/***************/
/* Interactive */
/***************/

var Interactive;
if (!Interactive) Interactive = {};

/*********************/
/* Interactive.Utils */
/*********************/

if (!Interactive.Utils) Interactive.Utils = {};

Interactive.Utils.textToHtml = function(text)
{
	return text.replace(/\n/g, '<br>').replace(/\r/g, '').replace(/\t/g, '');
}

Interactive.Utils.htmlToText = function(html)
{
	return html.replace(/\n/g, '').replace(/\r/g, '').replace(/<br>/gi, '\n').replace(/<br\/>/gi, '\n').replace(/\t/g, '');
}

Interactive.Utils.addEventListener = function(el, eventType, handler, capture)
{
	try
	{
		if (el.addEventListener)
			el.addEventListener(eventType, handler, capture);
		else if (el.attachEvent)
			el.attachEvent('on' + eventType, handler, capture);
	}catch (e) {}
};

Interactive.Utils.removeEventListener = function(el, eventType, handler, capture)
{
	try
	{
		if (el.removeEventListener)
			el.removeEventListener(eventType, handler, capture);
		else if (el.detachEvent)
			el.detachEvent("on" + eventType, handler, capture);
	}catch (e) {}
};

Interactive.Utils.stopEvent = function(event){
	try{
		if (event){
			if (event.stopPropagation)
				event.stopPropagation();
			else
				event.cancelBubble = true;

			if (event.preventDefault)
				event.preventDefault();
			else
				event.returnValue = false;
		}
	}catch (e){}
};

Interactive.Utils.findPosition = function(element)
{
	var position = new Object();
	position.left = 0;
	position.top = 0;

	if (element.offsetParent) {
		position.left = element.offsetLeft;
		position.top = element.offsetTop;
		while (element = element.offsetParent) {
			position.left += element.offsetLeft;
			position.top += element.offsetTop;
		}
	}
	return position;
}

Interactive.Utils.getScrollPosition = function()
{
	var scrollPosition = new Object();
	scrollPosition.scrollX = 0;
	scrollPosition.scrollY = 0;

	if(typeof(window.pageYOffset) == 'number') {
		//Netscape compliant
		scrollPosition.scrollX = window.pageXOffset;
		scrollPosition.scrollY = window.pageYOffset;
	} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scrollPosition.scrollX = document.body.scrollLeft;
		scrollPosition.scrollY = document.body.scrollTop;
	} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		//IE6 standards compliant mode
		scrollPosition.scrollX = document.documentElement.scrollLeft;
		scrollPosition.scrollY = document.documentElement.scrollTop;
	}
	return scrollPosition;
};

Interactive.Utils.getWindowSize = function()
{
	var windowSize = new Object();
	windowSize.width = 0;
	windowSize.height = 0;

	if( typeof( window.innerWidth ) == 'number') {
		//Non-IE
		windowSize.width = document.body.clientWidth;
		windowSize.height = document.body.clientHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		windowSize.width = document.documentElement.clientWidth;
		windowSize.height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		windowSize.width = document.body.clientWidth;
		windowSize.height = document.body.clientHeight;
	}

	return windowSize;
};

Interactive.Utils.isIE6orLess = function()
{
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if (version <= 6)
		return true;
	return false;
};

/***********************/
/* Interactive.Widgets */
/***********************/

if (!Interactive.Widgets) Interactive.Widgets = {};

/**********************************/
/* Interactive.Widgets.BaseWidget */
/**********************************/

Interactive.Widgets.BaseWidget = function() {}

Interactive.Widgets.BaseWidget.prototype.addAnchorEventListeners = function()
{
	var self = this;
	var addListener = Interactive.Utils.addEventListener;
	if (self.mouseClick)
		addListener(this.anchor, 'onclick', function(event){self.mouseClick(event);}, false);
	if (self.mouseDoubleClick)
		addListener(this.anchor, 'ondblclick', function(event){self.mouseDoubleClick(event);}, false);
	if (self.mouseDown)
		addListener(this.anchor, 'onmousedown', function(event){self.mouseDown(event);}, false);
	if (self.mouseUp)
		addListener(this.anchor, 'onmouseup', function(event){self.mouseUp(event);}, false);
	if (self.mouseOver)
		addListener(this.anchor, 'mouseover', function(event){self.mouseOver(event);}, false);
	if (self.mouseMove)
		addListener(this.anchor, 'mousemove', function(event){self.mouseMove(event);}, false);
	if (self.mouseOut)
		addListener(this.anchor, 'mouseout', function(event){self.mouseOutTimer = setTimeout(function(){self.mouseOut(event);}, 100)}, false);
};

/*******************************/
/* Interactive.Widgets.ToolTip */
/*******************************/

Interactive.Widgets.ToolTip = function(anchor, message, width, height)
{
	this.init(anchor, message, width, height);
	this.createIframeLayer();
	this.addAnchorEventListeners();
};

Interactive.Widgets.ToolTip.prototype = new Interactive.Widgets.BaseWidget;

Interactive.Widgets.ToolTip.prototype.init = function(anchor, message, width, height)
{
	this.width = width;
	this.height = height;
	this.anchor = document.getElementById(anchor);
	this.message = message;
	this.mouseOutTimer = null;
	this.shownEditor = false;
};

Interactive.Widgets.ToolTip.prototype.mouseOver = function(event)
{
	this.iframeLayer.style.display = 'block';
};

Interactive.Widgets.ToolTip.prototype.mouseOut = function(event)
{
	this.iframeLayer.style.display = 'none';
};

Interactive.Widgets.ToolTip.prototype.mouseMove = function(event)
{
	if (this.mouseOutTimer != null)
		clearTimeout(this.mouseOutTimer);
	var scrollPosition = Interactive.Utils.getScrollPosition();
	this.iframeLayer.style.left = scrollPosition.scrollX + event.clientX + 10;
	this.iframeLayer.style.top = scrollPosition.scrollY + event.clientY + 10;
};

Interactive.Widgets.ToolTip.prototype.createIframeLayer = function()
{
	var layer = document.createElement('iframe');
	layer.tabIndex = '-1';
	layer.src = '../js/interactive/widgets/toolTip.htm';
	layer.scrolling = 'no';
	layer.frameBorder = '0';
	layer.className = 'iwt-iframe';
	layer.id = 'iwtIframe';
	layer.style.width = this.width - 2;
	layer.style.height = this.height - 2;
	this.anchor.parentNode.appendChild(layer);
	this.iframeLayer = layer;
	var self = this;
	Interactive.Utils.addEventListener(this.iframeLayer, 'load', function(event){self.iframeLoad(event);}, false);
};

Interactive.Widgets.ToolTip.prototype.iframeLoad = function(event)
{
	this.iframeLayer.contentWindow.document.getElementById('iwtContentDiv').innerHTML = this.message;
};

/*******************************/
/* Interactive.Widgets.Editors */
/*******************************/

if (!Interactive.Widgets.Editors) Interactive.Widgets.Editors = {};

/**********************************************/
/* Interactive.Widgets.Editors.BaseTextEditor */
/**********************************************/

Interactive.Widgets.Editors.BaseTextEditor = function() {}

Interactive.Widgets.Editors.BaseTextEditor.prototype = new Interactive.Widgets.BaseWidget;

Interactive.Widgets.Editors.BaseTextEditor.prototype.init = function(anchor, params, callback, template)
{
	this.anchor = document.getElementById(anchor);
	this.maxLength = params;
	this.mouseOutTimer = null;
	this.callback = callback;
	this.template = template;
	this.shownPilotWindow = false;
};

Interactive.Widgets.Editors.BaseTextEditor.prototype.createIframeLayer = function(src, className)
{
	var pilotLayer = document.createElement('iframe');
	pilotLayer.tabIndex = '-1';
	pilotLayer.src = '../js/interactive/widgets/pilotFrame.htm';
	pilotLayer.scrolling = 'no';
	pilotLayer.frameBorder = '0';
	pilotLayer.className = 'pf-iframe';
	pilotLayer.allowTransparency = true;
	this.anchor.ownerDocument.body.appendChild(pilotLayer);
	//this.anchor.parentNode.appendChild(pilotLayer);
	this.iframePilotLayer = pilotLayer;
	this.iframePilotLayer.gebi = function(elementName) {
		return this.contentWindow.document.getElementById(elementName);
	}

	var editorLayer = document.createElement('iframe');
	editorLayer.tabIndex = '-1';
	editorLayer.src = src;
	editorLayer.scrolling = 'no';
	editorLayer.frameBorder = '0';
	editorLayer.className = className;
	editorLayer.allowTransparency = true;
	this.anchor.ownerDocument.body.appendChild(editorLayer);
	//this.anchor.parentNode.appendChild(editorLayer);
	this.iframeEditorLayer = editorLayer;
	this.iframeEditorLayer.gebi = function(elementName) {
		return this.contentWindow.document.getElementById(elementName);
	}
};

Interactive.Widgets.Editors.BaseTextEditor.prototype.destroy = function()
{
	this.anchor.ownerDocument.body.removeChild(this.iframeEditorLayer);
	this.anchor.ownerDocument.body.removeChild(this.iframePilotLayer);
}

Interactive.Widgets.Editors.BaseTextEditor.prototype.resize = function(event)
{
	var position = Interactive.Utils.findPosition(this.anchor);
	this.iframeEditorLayer.style.left = position.left;
	this.iframeEditorLayer.style.top = position.top;
	if (event != null && event.type == 'mouseover') {
		var scrollPosition = Interactive.Utils.getScrollPosition();
		this.iframePilotLayer.style.left = scrollPosition.scrollX + event.clientX - 45;
		this.iframePilotLayer.style.top = scrollPosition.scrollY + event.clientY - 85;
	}
};

Interactive.Widgets.Editors.BaseTextEditor.prototype.mouseOver = function(event)
{
	if (!this.shownPilotWindow) {
		this.resize(event);
		if (!this.shownEditor)
			this.iframePilotLayer.style.display = 'block';
			this.shownPilotWindow = true;
	}
};

Interactive.Widgets.Editors.BaseTextEditor.prototype.mouseOut = function(event)
{
	if (!this.shownEditor) {
		this.iframePilotLayer.style.display = 'none';
		this.shownPilotWindow = false;
	}
};

Interactive.Widgets.Editors.BaseTextEditor.prototype.mouseMove = function(event)
{
	if (this.mouseOutTimer != null)
		clearTimeout(this.mouseOutTimer);
};

Interactive.Widgets.Editors.BaseTextEditor.prototype.iframePilotLoad = function(event)
{
    var self = this;
	Interactive.Utils.addEventListener(this.iframePilotLayer, 'mouseout', function(event){self.mouseOutTimer = setTimeout(function(){self.mouseOut(event);}, 100);}, false);
	Interactive.Utils.addEventListener(this.iframePilotLayer, 'mouseover', function(event){self.mouseMove(event);}, false);
	Interactive.Utils.addEventListener(this.iframePilotLayer.gebi('editLink'), 'click', function(event){self.showEditor(event);}, false);
};

Interactive.Widgets.Editors.BaseTextEditor.prototype.addPilotEventListeners = function()
{
	var self = this;
	var addListener = Interactive.Utils.addEventListener;
	if (self.iframePilotLoad)
		addListener(this.iframePilotLayer, 'load', function(event){self.iframePilotLoad(event);}, false);
	if (self.iframeEditorLoad)
		addListener(this.iframeEditorLayer, 'load', function(event){self.iframeEditorLoad(event);}, false);
	/*
	if (self.resize)
		addListener(window, 'resize', function(event){self.resize(event);}, false);*/
};

/***************************************/
/* Interactive.Widgets.Editors.Gallery */
/***************************************/

Interactive.Widgets.Editors.Gallery = function(anchor, params, callback) {
	this.init(anchor, params, callback);
	this.srcs = params;
	this.createIframeLayer('../js/interactive/widgets/gallery.htm', 'gallery-iframe');
	this.addAnchorEventListeners();
	this.addPilotEventListeners();
};

Interactive.Widgets.Editors.Gallery.prototype = new Interactive.Widgets.Editors.BaseTextEditor();
Interactive.Widgets.Editors.Gallery.prototype.constructor = Interactive.Widgets.Editors.Gallery;

Interactive.Widgets.Editors.Gallery.prototype.iframeEditorLoad = function(event)
{
    var self = this;
	Interactive.Utils.addEventListener(this.iframeEditorLayer.gebi('iwemteIframeCloseLink'), 'click', function(event){self.hideEditor(event);}, false);
	this.iframeEditorLayer.gebi('galleryIframeScrollingDiv').innerHTML = '';
	var galleryIframeScrollingDiv = this.iframeEditorLayer.gebi('galleryIframeScrollingDiv');
	for (i = 0; i < this.srcs.length; i++) {
		var src = this.srcs[i];
		var div = this.iframeEditorLayer.contentWindow.document.createElement('div');
		div.className = 'gallery-iframe-thumb-div';
		galleryIframeScrollingDiv.appendChild(div);
		var img = this.iframeEditorLayer.contentWindow.document.createElement('img');
		img.src = src;
		img.alt = src;
		img.title = src;
		Interactive.Utils.addEventListener(img, 'mouseover', function(event){self.mouseOverThumb(event);}, false);
		Interactive.Utils.addEventListener(img, 'mouseout', function(event){self.mouseOutThumb(event);}, false);
		Interactive.Utils.addEventListener(img, 'click', function(event){self.clickThumb(event);}, false);
		div.appendChild(img);
	}
};

Interactive.Widgets.Editors.Gallery.prototype.showEditor = function(event)
{
	this.iframeEditorLayer.style.display = 'block';
	this.iframePilotLayer.style.display = 'none';
	this.shownPilotWindow = false;
	this.shownEditor = true;
};

Interactive.Widgets.Editors.Gallery.prototype.hideEditor = function(event)
{
	this.shownEditor = false;
	this.iframeEditorLayer.style.display = 'none';
};

Interactive.Widgets.Editors.Gallery.prototype.applyChangesEditor = function(event)
{
	this.hideEditor();
};

Interactive.Widgets.Editors.Gallery.prototype.mouseOverThumb = function(event)
{
	if (event.target)
		event.target.parentNode.className = 'gallery-iframe-thumb-selected-div';
	else
		event.toElement.parentElement.className = 'gallery-iframe-thumb-selected-div';
};

Interactive.Widgets.Editors.Gallery.prototype.mouseOutThumb = function(event)
{
	if (event.target)
		event.target.parentNode.className = 'gallery-iframe-thumb-div';
	else
		event.fromElement.parentElement.className = 'gallery-iframe-thumb-div';
};

Interactive.Widgets.Editors.Gallery.prototype.clickThumb = function(event)
{
	var src = (event.target ? event.target : event.srcElement);
	this.anchor.src = src.src;
	this.anchor.width = src.offsetWidth;
	this.anchor.height = src.offsetHeight;
	this.hideEditor();
};

/***************************************************/
/* Interactive.Widgets.Editors.MultilineTextEditor */
/***************************************************/

Interactive.Widgets.Editors.MultilineTextEditor = function(anchor, params, callback, template) {
	this.init(anchor, params, callback, template);
	this.createIframeLayer('../js/interactive/widgets/multilineTextEditor.htm', 'iwemte-iframe');
	this.addAnchorEventListeners();
	this.addPilotEventListeners();
};

Interactive.Widgets.Editors.MultilineTextEditor.prototype = new Interactive.Widgets.Editors.BaseTextEditor();
Interactive.Widgets.Editors.MultilineTextEditor.prototype.constructor = Interactive.Widgets.Editors.MultilineTextEditor;

Interactive.Widgets.Editors.MultilineTextEditor.prototype.iframeEditorLoad = function(event)
{
    var self = this;
	Interactive.Utils.addEventListener(this.iframeEditorLayer.gebi('applyLink'), 'click', function(event){self.applyChangesEditor(event);}, false);
	Interactive.Utils.addEventListener(this.iframeEditorLayer.gebi('closeLink'), 'click', function(event){self.hideEditor(event);}, false);
	Interactive.Utils.addEventListener(this.iframeEditorLayer.gebi('iwemteIframeTextArea'), 'keyup', function(event){self.updateStatusLine(event);}, false);
};

Interactive.Widgets.Editors.MultilineTextEditor.prototype.showEditor = function(event)
{
	this.iframeEditorLayer.gebi('iwemteIframeAvailableCharacters').innerHTML = this.maxLength;
	this.iframeEditorLayer.gebi('iwemteIframeTextArea').value = Interactive.Utils.htmlToText(this.template != null ? this.template : this.anchor.innerHTML);
	this.updateStatusLine();
	this.iframeEditorLayer.style.display = 'block';
	this.iframePilotLayer.style.display = 'none';
	this.shownPilotWindow = false;
	this.shownEditor = true;
};

Interactive.Widgets.Editors.MultilineTextEditor.prototype.hideEditor = function(event)
{
	this.shownEditor = false;
	this.iframeEditorLayer.style.display = 'none';
};

Interactive.Widgets.Editors.MultilineTextEditor.prototype.applyChangesEditor = function(event)
{
	var usedCharacters = this.iframeEditorLayer.gebi('iwemteIframeTextArea').value.length;
    if (usedCharacters > this.maxLength) {
		alert('You have entered too many characters. Limit is ' + this.maxLength + ' character(s)');
		return;
	}
    if (usedCharacters == 0) {
		alert('This field can not be empty');
		return;
	}
	var result = new Array();
	result[0] = Interactive.Utils.textToHtml(this.iframeEditorLayer.gebi('iwemteIframeTextArea').value);
	if (this.callback != null) {
		this.template = result[0];
		this.callback(this.anchor.id, result);
	} else
		this.anchor.innerHTML = result[0];
	this.hideEditor();
};

Interactive.Widgets.Editors.MultilineTextEditor.prototype.updateStatusLine = function(event)
{
	var usedCharacters = this.iframeEditorLayer.gebi('iwemteIframeTextArea').value.length;
	this.iframeEditorLayer.gebi('iwemteIframeStatusLine').style.color = (usedCharacters > this.maxLength ? 'red' : 'black');
	this.iframeEditorLayer.gebi('iwemteIframeUsedCharacters').innerHTML = usedCharacters;
};

/********************************************************/
/* Interactive.Widgets.Editors.BaseSinglelineTextEditor */
/********************************************************/

Interactive.Widgets.Editors.BaseSinglelineTextEditor = function() {}

Interactive.Widgets.Editors.BaseSinglelineTextEditor.prototype = new Interactive.Widgets.Editors.BaseTextEditor();

Interactive.Widgets.Editors.BaseSinglelineTextEditor.prototype.iframeEditorLoad = function(event)
{
    var self = this;
	Interactive.Utils.addEventListener(this.iframeEditorLayer.gebi('applyLink'), 'click', function(event){self.applyChangesEditor(event);}, false);
	Interactive.Utils.addEventListener(this.iframeEditorLayer.gebi('closeLink'), 'click', function(event){self.hideEditor(event);}, false);
};

Interactive.Widgets.Editors.BaseSinglelineTextEditor.prototype.hideEditor = function(event)
{
	this.shownEditor = false;
	this.iframeEditorLayer.style.display = 'none';
};

/****************************************************/
/* Interactive.Widgets.Editors.SinglelineTextEditor */
/****************************************************/

Interactive.Widgets.Editors.SinglelineTextEditor = function(anchor, params, callback, template) {
	this.init(anchor, params, callback, template);
	this.createIframeLayer('../js/interactive/widgets/singlelineTextEditor.htm', 'iweste-iframe');
	this.addAnchorEventListeners();
	this.addPilotEventListeners();
};

Interactive.Widgets.Editors.SinglelineTextEditor.prototype = new Interactive.Widgets.Editors.BaseSinglelineTextEditor();
Interactive.Widgets.Editors.SinglelineTextEditor.prototype.constructor = Interactive.Widgets.Editors.SinglelineTextEditor;

Interactive.Widgets.Editors.SinglelineTextEditor.prototype.showEditor = function(event)
{
	this.iframeEditorLayer.gebi('iwesteIframeTextField').maxLength = this.maxLength;
	this.iframeEditorLayer.gebi('iwesteIframeTextField').value = Interactive.Utils.htmlToText(this.template != null ? this.template : this.anchor.innerHTML);
	this.iframeEditorLayer.style.display = 'block';
	this.iframePilotLayer.style.display = 'none';
	this.shownPilotWindow = false;
	this.shownEditor = true;
};

Interactive.Widgets.Editors.SinglelineTextEditor.prototype.applyChangesEditor = function(event)
{
	var usedCharacters = this.iframeEditorLayer.gebi('iwesteIframeTextField').value.length;
    if (usedCharacters == 0) {
		alert('This field can not be empty');
		return;
	}
	var result = Interactive.Utils.textToHtml(this.iframeEditorLayer.gebi('iwesteIframeTextField').value);
	if (this.callback != null) {
		this.template = result;
		this.callback(this.anchor.id, result);
	} else
		this.anchor.innerHTML = result;
	
	this.hideEditor();
};

/******************************************/
/* Interactive.Widgets.Editors.LinkEditor */
/******************************************/

Interactive.Widgets.Editors.LinkEditor = function(anchor, params, callback, template) {
	this.init(anchor, params, callback, template);
	this.createIframeLayer('../js/interactive/widgets/linkEditor.htm', 'iwele-iframe');
	this.addAnchorEventListeners();
	this.addPilotEventListeners();
};

Interactive.Widgets.Editors.LinkEditor.prototype = new Interactive.Widgets.Editors.BaseSinglelineTextEditor();
Interactive.Widgets.Editors.LinkEditor.prototype.constructor = Interactive.Widgets.Editors.LinkEditor;

Interactive.Widgets.Editors.LinkEditor.prototype.showEditor = function(event)
{
	this.iframeEditorLayer.gebi('textFieldCaption').maxLength = this.maxLength[0];
	this.iframeEditorLayer.gebi('textFieldUrl').maxLength = this.maxLength[1];
	this.iframeEditorLayer.gebi('textFieldUrl').value = Interactive.Utils.htmlToText(this.template[0] != null ? this.template[0] : this.anchor.href);
	this.iframeEditorLayer.gebi('textFieldCaption').value = Interactive.Utils.htmlToText(this.template[1] != null ? this.template[1] : this.anchor.innerHTML);
	this.iframeEditorLayer.style.display = 'block';
	this.iframePilotLayer.style.display = 'none';
	this.shownPilotWindow = false;
	this.shownEditor = true;
};

Interactive.Widgets.Editors.LinkEditor.prototype.applyChangesEditor = function(event)
{
    if (this.iframeEditorLayer.gebi('textFieldCaption').value.length == 0 || this.iframeEditorLayer.gebi('textFieldUrl').value.length == 0) {
		alert('"Captin" and "URL" can\'t be empty');
		return;
	}
	var result = new Array();
	result[0] = Interactive.Utils.textToHtml(this.iframeEditorLayer.gebi('textFieldUrl').value);
	result[1] = Interactive.Utils.textToHtml(this.iframeEditorLayer.gebi('textFieldCaption').value);
	if (this.callback != null) {
		this.template[0] = result[0];
		this.template[1] = result[1];
		this.callback(this.anchor.id, result);
	} else {
		//this.anchor.href = result[0];
		this.anchor.innerHTML = result[1];
	}
	this.hideEditor();
};

/**********************/
/* Interactive.Popups */
/**********************/

if (!Interactive.Popups) Interactive.Popups = {};

/********************************/
/* Interactive.Popups.BasePopup */
/********************************/

Interactive.Popups.BasePopup = function() {}

Interactive.Popups.BasePopup.prototype.destroy = function()
{
	if (this.busyLayer != null)
	this.busyLayer.destroy();
	document.body.removeChild(this.iframeLayer);
};

Interactive.Popups.BasePopup.prototype.init = function(width, height, message, callbacks)
{
	this.width = width;
	this.height = height;
	this.message = message;
	this.callbacks = callbacks;
	this.busyLayer = new Interactive.Popups.BusyLayer(false);
};

Interactive.Popups.BasePopup.prototype.createIframeLayer = function(type)
{
	var iframe = document.createElement('iframe');
	iframe.tabIndex = '-1';
	iframe.src = '/popupWindow?type=' + type + '&width=' + (this.width - 30) + '&height=' + (this.height - 30);
	iframe.scrolling = 'no';
	iframe.frameBorder = '0';
	iframe.className = 'ipc-iframe';
	iframe.style.width = this.width;
	iframe.style.height = this.height;
	iframe.allowTransparency = true;
	document.body.appendChild(iframe);
	this.iframeLayer = iframe;
	this.resize();
	var self = this;
	Interactive.Utils.addEventListener(this.iframeLayer, 'load', function(){self.iframeLoad();}, false);
	this.iframeLayer.gebi = function(elementName) {
		return this.contentWindow.document.getElementById(elementName);
	}
};

Interactive.Popups.BasePopup.prototype.iframeLoad = function()
{
	var self = this;
	this.iframeLayer.gebi('message').innerHTML = this.message;
	if (this.iframeLayer.gebi('continueButton'))
		Interactive.Utils.addEventListener(this.iframeLayer.gebi('continueButton'), 'click', function(){self.continueClick();}, false);
	if (this.iframeLayer.gebi('cancelButton'))
		Interactive.Utils.addEventListener(this.iframeLayer.gebi('cancelButton'), 'click', function(){self.cancelClick();}, false);
	if (this.iframeLayer.gebi('closeButton'))
		Interactive.Utils.addEventListener(this.iframeLayer.gebi('closeButton'), 'click', function(){self.closeClick();}, false);
	Interactive.Utils.addEventListener(window, 'resize', function(){self.resize();}, false);
	Interactive.Utils.addEventListener(window, 'scroll', function(){self.resize();}, false);
};

Interactive.Popups.BasePopup.prototype.resize = function()
{
	var scrollPosition = Interactive.Utils.getScrollPosition();
	var windowSize = Interactive.Utils.getWindowSize();
	this.iframeLayer.style.left = (windowSize.width - this.width) / 2 + scrollPosition.scrollX;
	this.iframeLayer.style.top = (windowSize.height - this.height) / 2 + scrollPosition.scrollY;
};

/******************************/
/* Interactive.Popups.Confirm */
/******************************/

Interactive.Popups.Confirm = function(width, height, message, callbacks)
{
	this.init(width, height, message, callbacks);
	this.createIframeLayer('confirm');
};

Interactive.Popups.Confirm.prototype = new Interactive.Popups.BasePopup();
Interactive.Popups.Confirm.prototype.constructor = Interactive.Popups.BasePopup;

Interactive.Popups.Confirm.prototype.continueClick = function()
{
	this.destroy();
	if (this.callbacks[0])
		this.callbacks[0]();
};

Interactive.Popups.Confirm.prototype.cancelClick = function()
{
	this.destroy();
	if (this.callbacks[1])
		this.callbacks[1]();
};

Interactive.Popups.Confirm.prototype.closeClick = function()
{
	this.destroy();
};

/****************************/
/* Interactive.Popups.Alert */
/****************************/

Interactive.Popups.Alert = function(width, height, message, callbacks)
{
	this.init(width, height, message, callbacks);
	this.createIframeLayer('alert');
};

Interactive.Popups.Alert.prototype = new Interactive.Popups.BasePopup();
Interactive.Popups.Alert.prototype.constructor = Interactive.Popups.BasePopup;

Interactive.Popups.Alert.prototype.continueClick = function()
{
	this.destroy();
	if (this.callbacks)
		this.callbacks();
};

Interactive.Popups.Alert.prototype.closeClick = function()
{
	this.destroy();
};

/********************************/
/* Interactive.Popups.BusyLayer */
/********************************/

Interactive.Popups.BusyLayer = function(cancelable)
{
	this.init(cancelable);
	this.createIframeLayer();
	this.show();
};

Interactive.Popups.BusyLayer.prototype = new Interactive.Popups.BasePopup();
Interactive.Popups.BusyLayer.prototype.constructor = Interactive.Popups.BasePopup;

Interactive.Popups.BusyLayer.prototype.init = function(cancelable)
{
	this.cancelable = cancelable;
	this.selects = null;
};

Interactive.Popups.BusyLayer.prototype.createIframeLayer = function()
{
	var busyLayer = document.createElement('div');
	busyLayer.className = 'ipbl-div';
	if (Interactive.Utils.isIE6orLess())
		busyLayer.className += '-ie6';
	var windowSize = Interactive.Utils.getWindowSize();
	busyLayer.style.left = 0;
	busyLayer.style.top = 0;
	document.body.appendChild(busyLayer);
	this.busyLayer = busyLayer;
	this.resize();
	
	var self = this;
	Interactive.Utils.addEventListener(window, 'resize', function(){self.resize();}, false);
	if (this.cancelable)
		Interactive.Utils.addEventListener(this.busyLayer, 'click', function(){self.cancelClick();}, false);
};

Interactive.Popups.BusyLayer.prototype.resize = function()
{
	//this.busyLayer.style.width = 0;
	//this.busyLayer.style.height = 0;
	this.busyLayer.style.width = document.body.scrollWidth;
	this.busyLayer.style.height = document.body.scrollHeight;
};

Interactive.Popups.BusyLayer.prototype.cancelClick = function()
{
	this.destroy();
};

Interactive.Popups.BusyLayer.prototype.destroy = function()
{
	this.changeSelectsVisibility('visible');
	document.body.removeChild(this.busyLayer);
};

Interactive.Popups.BusyLayer.prototype.show = function()
{
	this.busyLayer.style.visibility = 'visible';
	if (Interactive.Utils.isIE6orLess()) {
		this.selects = document.getElementsByTagName('select');
		for(var index = 0; index < this.selects.length; index ++)
			if (this.selects[index].style.visibility == 'hidden')
				this.selects[index].ignore = true;
			else
				this.selects[index].ignore = false;
		this.changeSelectsVisibility('hidden');
	}
};

Interactive.Popups.BusyLayer.prototype.hide = function()
{
	this.changeSelectsVisibility('visible');
	this.busyLayer.style.visibility = 'hidden';
};

Interactive.Popups.BusyLayer.prototype.changeSelectsVisibility = function(visibility)
{
	if (this.selects)
		for(var index = 0; index < this.selects.length; index ++)
			if (!this.selects[index].ignore)
				this.selects[index].style.visibility = visibility;
};

/*****************************************/
/* Interactive.Widgets.SimpleDateChooser */
/*****************************************/

Interactive.Widgets.SimpleDateChooser = function(anchor)
{
	this.init(anchor);
	this.createIframeLayer();
	//this.addAnchorEventListeners();
};

Interactive.Widgets.SimpleDateChooser.prototype.init = function(anchor)
{
	this.anchor = document.getElementById(anchor);
	var d = new Date();
	this.month = d.getMonth();
	this.monthes = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	this.year = d.getFullYear();
	this.startYear = 1980;
	this.endYear = this.year;
	this.monthFirstTimer = null;
	this.yearFirstTimer = null;
	this.monthCycleTimer = null;
	this.yearCycleTimer = null;
	this.blurTimer = null;
	this.timerFirstInterval = 500;
	this.timerCycleInterval = 100;
	this.blurTimerInterval = 100;
	this.temp = null;
};

Interactive.Widgets.SimpleDateChooser.prototype.createIframeLayer = function()
{
	var iframe = document.createElement('iframe');
	iframe.tabIndex = '-1';
	iframe.src = '../js/interactive/widgets/simpleDateChooser.htm';
	iframe.scrolling = 'no';
	iframe.frameBorder = '0';
	iframe.className = 'sdc-iframe';
	iframe.allowTransparency = true;
	iframe.width = 150;
	iframe.height = 86;
	document.body.appendChild(iframe);
	this.iframeLayer = iframe;
	var self = this;
	Interactive.Utils.addEventListener(this.iframeLayer, 'load', function(){self.iframeLoad();}, false);
	this.iframeLayer.gebi = function(elementName) {
		return this.contentWindow.document.getElementById(elementName);
	}
};

Interactive.Widgets.SimpleDateChooser.prototype.iframeLoad = function()
{
	this.setMonth();
	this.setYear();
	
	var self = this;

	Interactive.Utils.addEventListener(this.anchor, 'focus', function(){self.show();}, false);
	Interactive.Utils.addEventListener(this.anchor, 'blur', function(event){self.blurTimer = setTimeout(function(event){self.lostFocus(event);}, self.blurTimerInterval);}, false);
	Interactive.Utils.addEventListener(window, 'resize', function(){self.positioning();}, false);
	Interactive.Utils.addEventListener(window, 'scroll', function(){self.positioning();}, false);
	
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('mainDiv'), 'mousedown', function(){setTimeout(function(){clearTimeout(self.blurTimer);}, 50);}, false);
	Interactive.Utils.addEventListener(document.body, 'mousedown', function(event){self.lostFocus(event);}, false);
	
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('monthLeft'), 'mouseover', function(event){self.navigatorMouseOver(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('monthLeft'), 'mouseout', function(event){self.navigatorMouseOut(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('monthLeft'), 'mousedown', function(){self.setMonth(-1); self.monthFirstTimer = setTimeout(function(){self.monthCycle(-1);}, self.timerFirstInterval);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('monthLeft'), 'mouseup', function(){clearTimeout(self.monthFirstTimer); clearTimeout(self.monthCycleTimer);}, false);

	Interactive.Utils.addEventListener(this.iframeLayer.gebi('monthRight'), 'mouseover', function(event){self.navigatorMouseOver(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('monthRight'), 'mouseout', function(event){self.navigatorMouseOut(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('monthRight'), 'mousedown', function(){self.setMonth(1); self.monthFirstTimer = setTimeout(function(){self.monthCycle(1);}, self.timerFirstInterval);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('monthRight'), 'mouseup', function(){clearTimeout(self.monthFirstTimer); clearTimeout(self.monthCycleTimer);}, false);

	Interactive.Utils.addEventListener(this.iframeLayer.gebi('yearLeft'), 'mouseover', function(event){self.navigatorMouseOver(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('yearLeft'), 'mouseout', function(event){self.navigatorMouseOut(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('yearLeft'), 'mousedown', function(){self.setYear(-1); self.yearFirstTimer = setTimeout(function(){self.yearCycle(-1);}, self.timerFirstInterval);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('yearLeft'), 'mouseup', function(){clearTimeout(self.yearFirstTimer); clearTimeout(self.yearCycleTimer);}, false);

	Interactive.Utils.addEventListener(this.iframeLayer.gebi('yearRight'), 'mouseover', function(event){self.navigatorMouseOver(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('yearRight'), 'mouseout', function(event){self.navigatorMouseOut(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('yearRight'), 'mousedown', function(){self.setYear(1); self.yearFirstTimer = setTimeout(function(){self.yearCycle(1);}, self.timerFirstInterval);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('yearRight'), 'mouseup', function(){clearTimeout(self.yearFirstTimer); clearTimeout(self.yearCycleTimer);}, false);

	Interactive.Utils.addEventListener(this.iframeLayer.gebi('close'), 'click', function(event){self.navigatorMouseOut(event); self.hide(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('close'), 'mouseover', function(event){self.navigatorMouseOver(event);}, false);
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('close'), 'mouseout', function(event){self.navigatorMouseOut(event);}, false);
};

Interactive.Widgets.SimpleDateChooser.prototype.setMonth = function(step)
{
	if (step) {
		if ((step == -1 && this.month > 0) || (step == 1 && this.month < 11)) {
			this.month = this.month + step;
		} else if (step == -1 && this.month == 0 && this.year > this.startYear) {
			this.month = 11;
			this.year = this.year - 1;
			this.iframeLayer.gebi('year').innerHTML = this.year;
		} else if (step == 1 && this.month == 11 && this.year < this.endYear) {
			this.month = 0;
			this.year = this.year + 1;
			this.iframeLayer.gebi('year').innerHTML = this.year;
		}
		this.outputToAnchor();
	}
	this.iframeLayer.gebi('month').innerHTML = this.monthes[this.month];
};

Interactive.Widgets.SimpleDateChooser.prototype.setYear = function(step)
{
	if (step) {
		if ((step == -1 && this.year > this.startYear) || (step == 1 && this.year < this.endYear))
			this.year = this.year + step;
		this.outputToAnchor();
	}
	this.iframeLayer.gebi('year').innerHTML = this.year;
};

Interactive.Widgets.SimpleDateChooser.prototype.navigatorMouseOver = function(event)
{
	if (event.target)
		event.target.className = 'sdc-navigate-div-active';
	else
		event.toElement.className = 'sdc-navigate-div-active';	
};

Interactive.Widgets.SimpleDateChooser.prototype.navigatorMouseOut = function(event)
{
	if (event.target)
		event.target.className = 'sdc-navigate-div';
	else if (event.fromElement)
		event.fromElement.className = 'sdc-navigate-div';
	else
		event.srcElement.className = 'sdc-navigate-div';
};

Interactive.Widgets.SimpleDateChooser.prototype.destroy = function(event)
{
	document.body.removeChild(this.iframeLayer);
};

Interactive.Widgets.SimpleDateChooser.prototype.monthCycle = function(step)
{
	var self = this;
	this.monthCycleTimer = setInterval(function(){self.setMonth(step);}, self.timerCycleInterval);
};

Interactive.Widgets.SimpleDateChooser.prototype.yearCycle = function(step)
{
	var self = this;
	this.yearCycleTimer = setInterval(function(){self.setYear(step);}, self.timerCycleInterval);
};

Interactive.Widgets.SimpleDateChooser.prototype.show = function(event)
{
	clearTimeout(this.blurTimer);
	this.positioning();
	this.iframeLayer.style.display = 'block';
};

Interactive.Widgets.SimpleDateChooser.prototype.hide = function(event)
{
	this.iframeLayer.style.display = 'none';
};

Interactive.Widgets.SimpleDateChooser.prototype.positioning = function(event)
{
	var position = Interactive.Utils.findPosition(this.anchor);
	var scrollPosition = Interactive.Utils.getScrollPosition();
	this.iframeLayer.style.left = position.left;
	this.iframeLayer.style.top = position.top + 18;
};

Interactive.Widgets.SimpleDateChooser.prototype.outputToAnchor = function()
{
	this.anchor.value = (this.month < 10 ? '0' + this.month : this.month)+ '/' + this.year;
};

Interactive.Widgets.SimpleDateChooser.prototype.lostFocus = function(event)
{
	clearTimeout(this.monthFirstTimer);
	clearTimeout(this.yearFirstTimer);
	clearTimeout(this.monthCycleTimer);
	clearTimeout(this.yearCycleTimer);
	this.hide();
};

/*****************************/
/*		Popup 		 */
/*****************************/

Interactive.Popups.Popup = function(url, id, isBusyLayer, width, height, continueCb) {
	this.init(url, id, isBusyLayer, width, height, continueCb);
	this.createIframeLayer();
}

Interactive.Popups.Popup.prototype = new Interactive.Popups.BasePopup();
Interactive.Popups.Popup.prototype.init = function(url, id, isBusyLayer, width, height, continueCb) {
	this.url = url;
	this.isBusyLayer = isBusyLayer;
	if (isBusyLayer)
		this.busyLayer = new Interactive.Popups.BusyLayer(false);
	this.width = width;
	this.height = height;
	this.continueCb = continueCb;
	this.id = id;
}

Interactive.Popups.Popup.prototype.createIframeLayer = function()
{
	var iframe = document.createElement('iframe');
	iframe.tabIndex = '-1';
	iframe.src = this.url;
	iframe.scrolling = 'no';
	iframe.frameBorder = '0';
	iframe.className = 'iprp-iframe';
	iframe.style.width = this.width;
	iframe.style.height = this.height;
	iframe.allowTransparency = true;
	iframe.id = this.id;
	document.body.appendChild(iframe);
	this.iframeLayer = iframe;
	this.resize();
	var self = this;
	Interactive.Utils.addEventListener(this.iframeLayer, 'load', function(){self.iframeLoad();}, false);
	this.iframeLayer.gebi = function(elementName) {
		return this.contentWindow.document.getElementById(elementName);
	}
};

Interactive.Popups.Popup.prototype.iframeLoad = function()
{
	var self = this;
	Interactive.Utils.addEventListener(this.iframeLayer.gebi('closeButton'), 'click', function(){self.closeClick();}, false);
	if (this.iframeLayer.gebi('cancelButton') != null)
		Interactive.Utils.addEventListener(this.iframeLayer.gebi('cancelButton'), 'click', function(){self.cancelClick();}, false);
	if (this.iframeLayer.gebi('continueButton') != null)
		Interactive.Utils.addEventListener(this.iframeLayer.gebi('continueButton'), 'click', function(){self.continueClick();}, false);
	Interactive.Utils.addEventListener(window, 'resize', function(){self.resize();}, false);
	Interactive.Utils.addEventListener(window, 'scroll', function(){self.resize();}, false);
};

Interactive.Popups.Popup.prototype.continueClick = function(result)
{
	this.iframeLayer.style.display = "none";
	if (this.continueCb)
		this.continueCb(result);
	this.destroy();
};

Interactive.Popups.Popup.prototype.cancelClick = function()
{
	this.destroy();
};

Interactive.Popups.Popup.prototype.closeClick = function()
{
	this.destroy();
};

Interactive.Popups.Popup.prototype.resize = function()
{
	var scrollPosition = Interactive.Utils.getScrollPosition();
	var windowSize = Interactive.Utils.getWindowSize();
	this.iframeLayer.style.left = (windowSize.width - this.width) / 2 + scrollPosition.scrollX;
	this.iframeLayer.style.top = (windowSize.height - this.height) / 2 + scrollPosition.scrollY;
};
